/**
 * DataUtil处理主页相关的数据请求
 */

import ApiURL from "./ApiURL.js";

class DataUtil {
  /**
   * 获取笑话列表数据
   */
  static getJokeList(previousJokeIds) {
    //创建一个承诺Promise
    var p = new Promise((resolve, reject) => {
      wx.request({
        url: ApiURL.getJokeURL(previousJokeIds),
        method: "GET",
        success: res => {
          resolve(res.data);
        },
        fail: err => {
          reject(err);
        }
      })
    });
    return p;
  }
  //根据贴子Id得到贴子回复信息
  static getCommentList(itemId){
    return new Promise((resolve,reject)=>{
      wx.request({
        url:ApiURL.commentListURL(itemId),
        method:"GET",
        success:res=>{
          resolve(res.data);
        },
        fail:err=>{
          reject(err);
        }
      })
    });
  }
  //获取图片的方法
  static getImageList(previousImageIds){
    return new Promise((resolve,reject)=>{
      wx.request({
        url: ApiURL.getImageListURL(previousImageIds),
        method:"GET",
        success:res=>{
          resolve(res.data);
        },
        fail:err=>{
          reject(err);
        }
      })
    });
  }
  static getVideoList(previousVideoIds){
    return new Promise((resolve,reject)=>{
      wx.request({
        url:ApiURL.getVideoListURL(previousVideoIds),
        method:"GET",
        success:res=>{
          resolve(res.data);
        },
        fail:err=>{
          reject(err);
        }
      })
    })
  }
  static getRecommendList(previousRecommendIds){
    return new Promise((resolve,reject)=>{
      wx.request({
        url: ApiURL.getRecommendListURL(previousRecommendIds),
        method:"GET",
        success:res=>{
          resolve(res.data);
        },
        fail:err=>{
          reject(err);
        }
      });
    });
  }
}

export default DataUtil;